clear 

* set directory 
* cd "directory"

* set paths
global datafolder "data"
global outputfolder "output"

********************************************************************************
*			Table 2: Actual rate and breakeven rate
********************************************************************************

	use "$datafolder\maindata.dta", clear
			
	keep if datem >= 660
	
	global cvars "OROA lDeposits lTotalAssets ratio_CurrentLiabilities "
	global loanChars "maturity_range has_coll_m_any lbalance"
	
	label variable actual_rate "Actual Rate"
	label variable theoretical_rate "Breakeven Rate"
	label variable OROA "OROA"
	label variable lDeposits "Deposits"
	label variable lTotalAssets "Assets"
	label variable ratio_CurrentLiabilities "Liabilities/Assets"
	label variable maturity_range "Maturity"
	label variable has_coll_m_any "Collateral"
	label variable lbalance "Loan Amount"

	* Actual ~ Theoretical (+ month FE, firm controls, type FE, firm FE)
		estimates clear
		
		* Column 1: AR ~ ThR
		quietly reg actual_rate c.theoretical_rate, cluster(customerid)
		quietly estadd local hasq "No"
		quietly estadd local hasind "No"
		quietly estadd local hasfirm "No"
		estimates store M1
		
		* Column 2: AR ~ ThR + quarter FE
		quietly reghdfe actual_rate c.theoretical_rate, ///
		abs(dateq) cluster(customerid)
		quietly estadd local hasq "Yes"
		quietly estadd local hasind "No"
		quietly estadd local hasfirm "No"
		estimates store M2
		
		* Column 3: AR ~ ThR + quarter FE + firm controls
		quietly reghdfe actual_rate c.theoretical_rate $cvars, ///
		abs(dateq) cluster(customerid)
		quietly estadd local hasq "Yes"
		quietly estadd local hasind "No"
		quietly estadd local hasfirm "No"
		estimates store M3
		
		* Column 4: AR ~ ThR + quarter FE + firm controls + loan controls
		quietly reghdfe actual_rate c.theoretical_rate $cvars $loanChars, /// 
		abs(dateq) cluster(customerid)
		quietly estadd local hasq "Yes"
		quietly estadd local hasind "No"
		quietly estadd local hasfirm "No"
		estimates store M4
		
		* Column 5: AR ~ ThR + quarter FE + firm controls + loan controls + ind FE
		quietly reghdfe actual_rate c.theoretical_rate $cvars $loanChars, ///
		abs(dateq Industry) cluster(customerid)
		quietly estadd local hasq "Yes"
		quietly estadd local hasind "Yes"
		quietly estadd local hasfirm "No"
		estimates store M5
		
		* Column 6: AR ~ ThR + quarter FE + firm FE + loan controls
		quietly reghdfe actual_rate c.theoretical_rate $loanChars, ///
		abs(firmid dateq) cluster(customerid)
		quietly estadd local hasq "Yes"
		quietly estadd local hasind "No"
		quietly estadd local hasfirm "Yes"
		estimates store M6
		
		esttab * using "$outputfolder\table_2.tex", replace  ///
		se star(* 0.1 ** 0.05 *** 0.01) b(3) se(3) r(3) ///
		nonotes r2 label nomtitles noomitted noconstant  ///
		scalars("hasq Quarter FE" "hasind Industry FE" "hasfirm Firm FE")
		
		